package com.exchange.controller.app.wallet;

import com.exchange.interceptor.BaseValidator;
import com.exchange.interceptor.EnumError;
import com.jfinal.core.Controller;
import com.jfinal.kit.Ret;

import cn.hutool.core.util.StrUtil;

public class WalletValidator extends BaseValidator {

	protected void validate(Controller c) {
		setRet(Ret.fail());
		this.setShortCircuit(true);//短路型验证
		
	    String url = getActionKey();
	    if (url.equals("/app/wallet/info")) {
	    	validateRequiredString("coin", "msg", EnumError.PARAMETER_ARE_MISSING.getCode());
        }
	    if (url.equals("/app/wallet/flow")) {
	    	validateInteger("pageNumber", "msg", EnumError.PARAMETER_ARE_MISSING.getCode());
	    	if(StrUtil.isNotBlank(c.getPara("dateFrom"))) {
	    		validateDate("dateFrom", "msg", EnumError.PARAMETER_ARE_MISSING.getCode());
	    	}
	    	if(StrUtil.isNotBlank(c.getPara("dateTo"))) {
	    		validateDate("dateTo", "msg", EnumError.PARAMETER_ARE_MISSING.getCode());
	    	}
        }
	    if (url.equals("/app/wallet/transfer")) {
	    	validateRequiredString("coin", "msg", EnumError.PARAMETER_ARE_MISSING.getCode());
	    	validateBigDecimalValue("amount", "msg", EnumError.PARAMETER_ARE_MISSING.getCode());
	    	if (c.getPara("fromType") == null || c.getPara("toType") == null || c.getPara("fromType").equals(c.getPara("toType"))) {
				addError("msg", EnumError.PARAMETER_ARE_MISSING.getCode());
			}
        }
	    
	    
		
	}
	
}

	